package com.davies.learn.jbv.controller;


import com.davies.learn.jbv.domain.dto.QueryPageDTO;
import com.davies.learn.jbv.domain.dto.UserSaveDTO;
import com.davies.learn.jbv.domain.dto.UserQueryDTO;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author davies
 * @date 2023/7/16 10:08
 */
@RestController
@Validated
public class HelloController {

    /**
     *
     * @see com.davies.learn.autoconfigure.QueryPageValueExtractor
     * @param queryPage 分页查询参数
     * @return "success"
     */
    @PostMapping("/page")
    public String queryPage(@RequestBody @Validated QueryPageDTO<@Valid UserQueryDTO> queryPage) {

        return "success";
    }


    /**
     * 因为内置了ListValueExtractor,MapValueExtractor,所以这里可以直接用 List<@Valid UserCreateDTO>
     * @param userDTO 保存用户
     * @return
     */
    @PostMapping("/user")
    public Object saveUser(@RequestBody @Validated List<@Valid UserSaveDTO> userDTO) {
        return userDTO;
    }



}
